public class Main {
    public static void main(String[] args){

        System.out.println("升级前：");
        Robot cxk = new Robot();
        cxk.calc();

        System.out.println("注入升级包后：");
        Visitor update = new UpdateVisitor();
        cxk.accept(update);
        cxk.calc();
    }
}

interface Visitor{
    void visitCPU(CPU cpu);

}
class UpdateVisitor implements Visitor{ //升级包
    @Override
    public void visitCPU(CPU cpu){
        cpu.command +="、打篮球"; //增加指令
    }

}
abstract class HardWare{
    String command;
    public  HardWare(String command){
        this.command = command;
    }
    public void  run(){
        System.out.println(command);
    }
    public abstract void accept(Visitor visitor);


}

class CPU extends HardWare{
    public CPU(String command){
        super(command);

    }
    @Override
    public void accept(Visitor visitor){
        visitor.visitCPU(this);
    } //入口函数
}


class Robot{
    private CPU cpu;

    public Robot(){
        cpu = new CPU("唱、跳");
    }
    public void calc(){
        cpu.run();
    }

    public void accept(Visitor visitor){
        cpu.accept(visitor);

    }
}